<!--
* description: CC工单-详情
* author: wangjuan
* createdDate: 2021-3-4
-->
<template>
  <section class="audit">
    <el-dialog
      v-dialogDrag
      :visible.sync="curPopupsVisible"
      :title="textMap"
      :append-to-body="true"
      width="85%"
      :close-on-click-modal="false"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="textMap"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-title">基本信息</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList1" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents1.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :format="comp.format"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :data-to-object="comp.dataToObj"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div class="filter-container filter-title">客户信息</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList2" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents2.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :format="comp.format"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :data-to-object="comp.dataToObj"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>
      <div class="filter-container filter-title">门店反馈信息</div>
      <div class="app-container app-container-table">
        <mix-table
          ref="tableList"
          :is-dialog="true"
          :is-more="true"
          :is-paging="false"
          :dynamic-table-cols="dynamictableCols"
          :table-height="200"
        />
      </div>
      <div class="filter-container filter-title">服务运营审核信息</div>
      <div class="app-container app-container-table">
        <one-table-template
          ref="multipleTable"
          :dynamic-buttons="tableButtons"
          :dynamic-components="tableComponents3"
          :dynamic-form-fields="formField"
        />
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { formMixins } from '@/components/mixins/formMixins'
import mixTable from '@/components/basicComponent/mixTable'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/caseManagementQuery'

export default {
  components: {
    OneTableTemplate,
    mixTable,
    dialogHeader: () => import('@/components/dialogHeader')
  },

  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins, formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: { type: Object, default: function() { return {} } }
  },

  data() {
    const viewPageCode = 'ccdetail-edit'

    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.pass(),
          text: '同意',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.reject(),
          text: '驳回',
          position: 'right'
        }
      ],

      // 动态组件-查询条件
      tableComponents1:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '服务单编号：',
              codeField: 'orderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey2',
              labelName: '派单日期：',
              codeField: 'orderSendDate',
              component: () =>
                import('@/components/org/datePicker/datePicker.vue'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey3',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey4',
              labelName: '门店名称：',
              codeField: 'dlrName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey5',
              labelName: '工单状态：',
              codeField: 'orderStatusName',
              customObj: {
                api: orgApis.workStatus
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true,
              disabled: true,
              span: 6
            },
            {
              compKey: 'compKey6',
              labelName: '工单类型：',
              codeField: 'orderTypeName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey7',
              labelName: '一级分类：',
              codeField: 'firstClass',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey8',
              labelName: '二级分类：',
              codeField: 'secondClass',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey9',
              labelName: '三级分类：',
              codeField: 'thirdClass',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey10',
              labelName: '车辆位置：',
              codeField: 'carSite',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey11',
              labelName: '案例内容：',
              codeField: 'orderRemark',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 24
            }
          ],
      tableComponents3: [
        {
          compKey: 'compKey30',
          labelName: '审核意见：',
          codeField: 'checkRemark',
          component: () => import('@/components/org/commonInput/textareaInput'),
          type: 'inputText',
          disabled: false,
          isMul: false,
          isMust: true,
          span: 24
        }
      ],
      tableComponents2:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'compKey12',
              labelName: '客户姓名：',
              codeField: 'custName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey13',
              labelName: '性别：',
              codeField: 'sex',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey14',
              labelName: '客户电话：',
              codeField: 'custMobile',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey15',
              labelName: '客户类型：',
              codeField: 'custType',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey16',
              labelName: 'VIN码：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey17',
              labelName: '车系：',
              codeField: 'carSeries',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey18',
              labelName: '车型：',
              codeField: 'carType',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey19',
              labelName: '车牌号：',
              codeField: 'carNumber',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey22',
              labelName: '内饰颜色：',
              codeField: 'innerColor',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey23',
              labelName: '购车日期：',
              codeField: 'buyDate',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey24',
              labelName: '交付门店编码：',
              codeField: 'deliverDlrcode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey25',
              labelName: '交付门店名称：',
              codeField: 'deliverDlrname',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey26',
              labelName: 'ICCID：',
              codeField: 'iccid',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey27',
              labelName: 'PDSN：',
              codeField: 'pdsn',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey28',
              labelName: 'IMEI：',
              codeField: 'imei',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span: 6
            }
          ],
      tableComponents: [],
      dynamictableCols: [
        {
          codeField: 'releaseId',
          label: '主键ID',
          hidden: true,
          alwaysHidden: true
        },
        {
          codeField: 'updateControlId',
          label: '并发控制ID',
          hidden: true,
          alwaysHidden: true
        },
        {
          codeField: 'dlrReviewDate',
          label: '反馈时间',
          align: 'center'
        },
        {
          codeField: 'dlrReviewRemark',
          label: '反馈详情',
          align: 'center'
        }
      ],
      // 标题
      textMap: 'CC工单审核',

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        orderCode: '',
        orderSendDate: '',
        dlrCode: '',
        dlrName: '',
        orderStatusName: '',
        orderTypeName: '',
        thirdClass: '',
        carSite: '',
        orderRemark: '',

        custName: '',
        sex: '',
        custMobile: '',
        custType: '',
        vin: '',
        carSeries: '',
        carType: '',
        carNumber: '',
        carConfigure: '',
        engineType: '',
        innerColor: '',
        checkRemark: ''

      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode]),

      callbackObj: {
        // 当选择项发生变化时会触发该事件（多选时）
        onCheckSelectChange: (selection) => {
          this.selectData = selection

          this.handleSelectionChange(selection)
        }
      }
    }
  },
  watch: {
    curPopupsVisible: {
      handler: function(val) {
        if (val) {
          this.$nextTick(() => {
            this.formField = Object.assign(this.formField, this.dynamicEditRowData)
          })
          this.queryFeedBack()
        }
      }
    }
  },
  created() {
    this.tableComponents = [...this.tableComponents1, ...this.tableComponents2, ...this.tableComponents3]
  },

  methods: {
    // 门店信息-反馈信息查询
    queryFeedBack() {
      const that = this
      const queryObj = {
        apiConfig: orgApis.queryFeedBack,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          // 当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: that.dynamicEditRowData
        }
      }
      // 转换了中台请求格式数据
      var paramD = that.$getParams(queryObj)
      // 调用中台API方法（可复用）
      that.$requestAPI(paramD).then((response) => {
        that.$refs.tableList.tableData = response.rows
      })
    },
    // 审核通过
    pass() {
      const sendDatas = {
        checkRemark: this.formField.checkRemark,
        orderId: this.dynamicEditRowData.orderId,
        orderCode: this.formField.orderCode
      }
      this.sendMethods(sendDatas, orgApis.review)
    },

    // 审核通过
    reject() {
      const sendDatas = {
        checkRemark: this.formField.checkRemark,
        orderId: this.dynamicEditRowData.orderId,
        orderCode: this.formField.orderCode
      }
      this.sendMethods(sendDatas, orgApis.turnDown)
    },
    // 公共方法
    sendMethods(sendDatas, sendApi) {
      const queryObj = {
        type: 'mutation',
        apiConfig: sendApi,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: sendDatas
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      this.$requestAPI(paramD).then((response) => {
        if (response.result === '1') {
          this.$message({
            message: response.msg
          })
        } else {
          this.$message({
            message: response.msg
          })
        }
        this.$parent.queryTable()
        this.curPopupsVisible = false
      })
    },
    closeEdit() {
      this.$emit('update:popupsVisible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.btns-container {
  width: 100%;
  height: 30px;
  padding: 0 20px;
  background-color: #fff;
  .el-button {
    float: right;
    margin-left: 10px;
  }
}
  .filter-title{
    font-size: 18px;
    font-weight: bolder;
  }
  .filter-container.filter-title::before{
    border-left: 4px solid #0075FF;
    padding-right: 10px;
    height: 20px;
    left: 0px;
    top: 4px;
  }
</style>

